package io;

import jdk.nashorn.internal.runtime.Context;

import java.io.*;
import java.util.Scanner;

public class NoteDemo1 {
    public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入文件名:");
        String s = scanner.nextLine();
        FileOutputStream fos = new FileOutputStream(s);
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        /*
             PrintWriter构造方法中如果第一个参数是一个流,那么就支持一个boolean型的参数,
             表示自动行刷新.当这个参数为true时就打开了自动行刷新,此时每当通过PrintWriter
             的println方法写出一行字符串后就会自动flush一次.
             注意:print方法不会自动刷新
         */
        PrintWriter pw = new PrintWriter(bw,true);
        System.out.println("输入内容,输入输入exit退出:");
        String c;
        while (!"exit".equals(c = scanner.nextLine())) {
            pw.println(c);
        }
        pw.close();
    }
}
